package com.monkeybrother.thread.thread;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;

/**
 * @Desc
 * @Author houry
 * @Date 2021/2/8 15:20
 **/
public class MyThreadPool {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                10,
                10,
                10L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(10),
                new MyThreadFactory("小猴子自定义线程池"),
                new ThreadPoolExecutor.DiscardPolicy());
        try {
            IntStream.range(0, 20).forEach(v ->{
                pool.execute(() -> System.out.println("自定义线程池的名称：" +Thread.currentThread().getName()));
            });
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            pool.shutdown();
        }
    }

}